<?php
/*前台父级控制器*/
namespace app\common\controller;

use think\Controller;

class IndexBase extends Controller
{
    private $nav;
	protected function _initialize()
    {

        parent::_initialize();
        //获取网站配置信息
        $web = db('system')->where(['name'=>'site_config'])->value('value');
        $this->nav = $this->getMenu(1);//导航
        $this->assign([
        	'web'=>unserialize($web),
            'nav'=>$this->nav,
        ]);
        $newscate = db('newscate')
            ->where('isen','<>',1)
            ->order('weight desc')
            ->select();
        $newscate_en = db('newscate')
            ->where('isen','=',1)
            ->order('weight desc')
            ->select();
        $productscate = db('productcate')
            ->where('isen','<>',1)
            ->order('weight desc')
            ->select();
        $productscate_en = db('productcate')
            ->where('isen','=',1)
            ->order('weight desc')->select();
        $aboutuss[0] = db('pageinfo')->find(1);
        $aboutuss[1] = db('pageinfo')->find(2);
        $aboutuss[2] = db('pageinfo')->find(3);
        $rdcenter[0] = db('pageinfo')->find(4);
        $rdcenter[1] = db('pageinfo')->find(5);
        $make[0] = db('pageinfo')->find(6);
        $make[1] = db('pageinfo')->find(7);
        $this->assign('newscate',$newscate);
        $this->assign('newscate_en',$newscate_en);
        $this->assign('productscate',$productscate);
        $this->assign('productscate_en',$productscate_en);
        $this->assign('aboutuss',$aboutuss);
        $this->assign('rdcenter',$rdcenter);
        $this->assign('make',$make);
        $banner = db('ads')->where('isen','<>',1)->select();
        $banner_en = db('ads')->where('isen','=',1)->select();
        $this->assign('banner',$banner);
        $this->assign('banner_en',$banner_en);
        //halt($banner);
//        halt($this->nav);

    }
    protected function getMenu($nav_cid)
    {
        $menu = db('nav')->where(['nav_cid'=>$nav_cid,'status'=>1])->order(['sort' => 'DESC', 'id' => 'ASC'])->select();

        $menu = !empty($menu) ? list_to_tree($menu,'id','pid','child') : [];
        return $menu;
    }
}